package com.example.artemis.events;

/**
 * 消息处理成功事件
 * 当消息成功被消费者处理时触发此事件
 */
public class MessageProcessedEvent extends MessageEvent {

    private final String consumerId;
    private final long processingTime;
    private final int deliveryAttempt;
    private final long messageAge;

    public MessageProcessedEvent(String messageId, String queueName, String consumerId,
                                long processingTime, int deliveryAttempt, long messageAge) {
        super(messageId, queueName);
        this.consumerId = consumerId;
        this.processingTime = processingTime;
        this.deliveryAttempt = deliveryAttempt;
        this.messageAge = messageAge;
    }

    /**
     * 获取消费者ID
     */
    public String getConsumerId() {
        return consumerId;
    }

    /**
     * 获取消息处理耗时（毫秒）
     */
    public long getProcessingTime() {
        return processingTime;
    }

    /**
     * 获取消息投递尝试次数
     */
    public int getDeliveryAttempt() {
        return deliveryAttempt;
    }

    /**
     * 获取消息年龄（毫秒）- 从创建到处理完成的总时间
     */
    public long getMessageAge() {
        return messageAge;
    }

    @Override
    public String getEventType() {
        return "MESSAGE_PROCESSED";
    }

    @Override
    public String toString() {
        return String.format("MessageProcessedEvent{messageId='%s', queueName='%s', consumerId='%s', " +
                "processingTime=%dms, deliveryAttempt=%d, messageAge=%dms, timestamp=%d}",
                getMessageId(), getQueueName(), consumerId, processingTime, deliveryAttempt, messageAge, getTimestamp());
    }
}